package com.air.repo.design.pattern.singleton;

/**
 * Place Function on Here:
 *
 * @author yh 2018/7/12 13:36
 * @since: Jdk 1.8
 */
public class Singleton4 {

    private  static class Singleton4Holder {
        public static final Singleton4 instance=new Singleton4();
    }

    private static boolean oneTime=false;

    private Singleton4() {

        synchronized (Singleton4.class){
            if(oneTime==false){
                oneTime=true;
            }else{
                throw new RuntimeException("单例模式被侵犯！");
            }
        }
    }

    public static Singleton4 getInstance(){
        return Singleton4Holder.instance;
    }

}
